package com.cci.kangdao.dao;

import com.cci.kangdao.dao.model.CompanyT;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mybatis.spring.annotation.MapperScan;

import java.util.List;
import java.util.Map;

/**
 * 企业类dao
 *
 */
@MapperScan
public interface CompanyTDao {

	/**
	 * 根据服务站id获取所有服务渠道   不要BFCEC的
	 * @param type
	 * @return
	 */
	@Select("select a.id,a.CompanyNo,a.Abbreviation as CompanyName,a.IsOnline,b.BusinessNo from Company_T a \r\n" +
			"inner join SSRepair_T b on a.id = b.CompanyID\r\n" +
			"where b.ServiceStationID = #{serviceStationID} and a.CompanyNo not in('BFCEC')  \r\n" +
			"and a.Flag = 0 and b.Flag =0 order by case when a.CompanyNo='DCEC' then 0 else 1 end")
	public List<Map<String, Object>> getServiceChannelByServiceStationId(Map<String, Object> map);

	//根据服务站id获取该服务站所有的服务渠道的主键id
	@Select("select b.* from SSRepair_T a\n" +
			"inner join Company_T b on a.CompanyID=b.ID\n" +
			"where a.ServiceStationID=#{ServiceStationID} and a.Flag=0 and b.Flag=0")
	List<Map<String,Object>> getServiceChannelByStationId(long ServiceStationID);

	/**
	 * 根据CRM返回的CompanyNo获取对应的企业信息
	 * @param CompanyNo
	 * @return
	 */
	@Select("SELECT * FROM Company_T WHERE CompanyNo = #{CompanyNo} AND Flag = 0")
	public CompanyT getCompanyInfoByCompanyNo(String CompanyNo);

	/**
	 * 根据企业id获取企业信息
	 * @param CompanyID
	 * @return
	 */
	@Select("select * from Company_T where ID=#{CompanyID} and Flag=0")
	public CompanyT getCompanyInfoByCompanyID(long CompanyID);

	/**
	 * 通过企业名称查询企业信息（为1或3）
	 * @param companyName 企业名称
	 * @return
	 */
	@Select("select * from Company_T where CompanyName=#{companyName} and Flag=0 and IsType in (1,3)")
	CompanyT getCompanyInfoByCompanyName(String companyName);

	@Select("select * from Company_T where Flag=0 and (IsType =1 or IsType = 3)")
	List<CompanyT> getCompanyList();

	List<Map<String, Object>> getCompanysGuidanz(@Param("keywords") String keywords);

	List<CompanyT> getOMECompanyList(@Param("keyword") String keyword);

	List<Map<String, Object>> getServiceStationByCompanyId(@Param("companyId")Long companyId, @Param("keywords") String keywords);

	List<Map<String, Object>> getSubServiceStationByCompanyId(@Param("companyId")Long companyId, @Param("keywords") String keywords);
}
